var tblSchedule;
$(function () {
    tblSchedule = $('#tbl-schedule').DataTable(buildlScheduleOptions());
    trCssEvent(tblSchedule);
    $("#btn-search-schedule").click(scheduleSearch);
});

function buildlScheduleOptions() {
    var options = {
        "deferRender": true,
        "searching": false,
        "ordering": true,
        "processing": true,
        "scrollX": true,
        "language": {
            "url": plugPath + 'DataTables/chinese.json'
        },
        "serverSide": true,
        "ajax": {
            "url": basePath + "teacher/getScheduleData",
            "type": 'POST',
            data: function (params) {
                params['childId'] = $("#childId").val();
                params['name'] = $("#projectName").val();
                params['code'] = $("#courseType").val();
                params['scheduleDetailId'] = $("#scheduleId").val();

            }
        },

        "columns": [{
            "data": "category"
        }, {
            "data": "name"
        }, {
            "data": "dqnlnlStr"
        }, {
            "data": "dqnlnjStr"
        }, {
            "data": "dqnddjStr"
        }, {
            "data": "vqtStr"
        }, {
            "data": "ljtgcs"
        }, {
            "data": "code"
        }
        ],

        columnDefs: [{
            "targets": 7,
            "data": "id",
            "render": function (data, type, row, meta, full) {
                var childId = $("#childId").val();
                var name = row.category;
                if (name == "视觉能力") {
                    return '<button class="btn btn-primary" >测评信息</button>' +
                        '<button type="submit" class="btn btn-primary"  onclick="visualAbility(&quot;' + row.code + '&quot;);" >视觉能力调整 </button>' +
                        '<button type="submit" class="btn btn-primary"  onclick="visualDelect(&quot;' + row.code + '&quot;);" >剔除 </button>' +
                        '<button type="submit" class="btn btn-primary"  onclick="visualReplace(&quot;' + row.code + '&quot;);" >替换 </button>';
                } else if (name = "听觉能力") {
                    return '<button class="btn btn-primary" >测评信息</button><button type="submit" class="btn btn-primary"  onclick="auditoryAbility(' + row.code + ');" >听觉能力调整 </button>';
                }

            }
        }, {"orderable": false, "targets": [0, 2, 3, 4, 5, 6]}
        ],

        "dom": "<'row'<'col-xs-12't>><'row'<'col-xs-2 lstyle'l><'col-xs-3'i><'col-xs-6  fright'p>>"

    };
    return options;
}


//查询搜索中心
function scheduleSearch() {
    $("#btn-search-schedule").attr("disabled", "disabled");
    tblSchedule.ajax.reload(function () {
        $("#btn-search-schedule").removeAttr("disabled");
    });
}

//听觉能力调整
function auditoryAbility(code) {
    var scheduleId= $("#scheduleId").val();
    var childId = $("#childId").val();
    var url = basePath + "teacher/goAuditoryAbilityPage";
    $("#auditory-page").load(url, {
        code: code, childId: childId,scheduleId:scheduleId
    }, function () {
    });
}

//视觉能力调整
function visualAbility(code) {
    var childId = $("#childId").val();
    var scheduleId= $("#scheduleId").val();
    var url = basePath + "teacher/goVisualAbilityPage";
    $("#visual-ability").load(url, {
        code: code, childId: childId,scheduleId:scheduleId
    }, function () {
    });
}

//视觉整体调整
function visualDelect(code) {
    var childId = $("#childId").val();
    var scheduleId= $("#scheduleId").val();
    var url = basePath + "teacher/goVisualAdd";
    $("#visual-replace-model").load(url, {
        code: code, childId: childId,scheduleId:scheduleId
    }, function () {
    });
}

//视觉能力调整
function visualReplace(code) {
    var childId = $("#childId").val();
    var scheduleId= $("#scheduleId").val();
    var url = basePath + "teacher/goVisualReplace";
    $("#visual-replace-model").load(url, {
        code: code, childId: childId,scheduleId:scheduleId
    }, function () {
    });
}
